package presentation;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import edu.cmu.sphinx.speech.recognition.SpeechRec;

/*
 * On this screen you can see with how many players you are going to play the game and you can change it. 
 */

public class NumberOfPlayersPanel extends JPanel {

	private ImageIcon background =
            new ImageIcon ("gamebackground1.jpg");
	
	//number of players initially on 2
	private static int number = 2;
	private static JLabel numberLabel;
	public static SpeechRec speak;
	private static JPanel numberPanel, nPanel;
	
	/**
	 * Create the panel.
	 */
	public NumberOfPlayersPanel() {
		this.setLayout(null);
		
		nPanel = new JPanel();
		numberLabel = new JLabel("Number of players: " + number);
		numberPanel = this;
		Initialize();
	}
	
	private static void Initialize(){
		
		
	    numberLabel.setLocation(0, 0);
	    numberLabel.setSize(150, 30);
	    numberLabel.setHorizontalAlignment(0);

	    nPanel.add(numberLabel);
	    nPanel.setLayout(null);
	    nPanel.setSize(150, 30);
	    nPanel.setBackground(Color.CYAN);
	    numberPanel.add(nPanel);

	}
	
	//Set background and size
	@Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(background.getImage(), 0, 0, null);
    }

    @Override
    public Dimension getPreferredSize() {
        return new Dimension(
        	background.getImage().getWidth(null),
        	background.getImage().getHeight(null));
    }
    
    //Change the label accordingly to the voice input
    public void changeLabel(int n){
    	number = n;
    	System.out.println("in changelabel: " + number);
    	numberLabel.setText("Number of players: " + number);    	
    	
    }
    public static  int getNumber(){
    	return number;
    }
    
    // number of players --> 1-5 players
    public int changeNumber(){

    	int index = speak.giveNumber();
    	switch(index){
    	case 2:  index = 2;
    		break;
    	case 7:  index = 7;
    		changeLabel(1);
    		break;
    	case 8:  index = 8;
    		changeLabel(2);
    		break;
    	case 9: index = 9;
    		changeLabel(3);
    		break;
    	case 10: index = 10;
    		changeLabel(4);
    		break;
    	case 11: index = 11;
    		changeLabel(5);
			break;
    	}
    	return index;
    }

}
